package com.cwz.service;

import com.cwz.entity.User;
import com.cwz.exception.ErrorEnum;
import com.cwz.exception.ServiceException;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wenZhen
 * @create 2024-08-17 11:52
 */
public interface IService {

    default Map<String,Object> success(Object data){
        Map<String,Object> map=new HashMap<>();
        map.put("code",ErrorEnum.SUCCESS.getCode());
        map.put("msg",ErrorEnum.SUCCESS.getMsg());
        map.put("data",data);
        return map;
    }


    default Map<String,Object> success(){
        Map<String,Object> map=new HashMap<>();
        map.put("code",ErrorEnum.SUCCESS.getCode());
        map.put("msg",ErrorEnum.SUCCESS.getMsg());
        return map;
    }

    String ADMIN_ROLE="管理员";

    default void checkAdminRole(HttpSession session){
        User user = (User) session.getAttribute("user");
        if (!ADMIN_ROLE.equals(user.getRole())){
            throw new ServiceException(ErrorEnum.PERMISSION_DENIED);
        }
    }

}
